package com.hiof.antplus;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import com.hiof.settings.SettingManager;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 6/19/12
 * Time: 12:34 AM
 * To change this template use File | Settings | File Templates.
 */
public class AntPlusServiceConnection implements ServiceConnection {
    private AntPlusManager mAntManager;
    private AntPlusManager.Callbacks callbacks;

    public AntPlusServiceConnection(AntPlusManager.Callbacks callbacks) {
        this.callbacks = callbacks;
    }

    @Override
    public void onServiceConnected(ComponentName componentName, IBinder service) {
        mAntManager = ((ANTPlusService.LocalBinder) service).getManager();
        mAntManager.setCallbacks(callbacks);
        loadConfiguration();
//        notifyAntStateChanged();

        /*if (mShownDialog != null) {
            mShownDialog.setEnabled(true);
            switch (mShownDialog.getId()) {
                case PairingDialog.HRM_ID:
                    mShownDialog.setDeviceNumber(mAntManager
                            .getDeviceNumberHRM());
                    break;
                case PairingDialog.SDM_ID:
                    mShownDialog.setDeviceNumber(mAntManager
                            .getDeviceNumberSDM());
                    break;
                case PairingDialog.WGT_ID:
                    mShownDialog.setDeviceNumber(mAntManager
                            .getDeviceNumberWGT());
                    break;
                case PairingDialog.BUFF_ID:
                    mShownDialog.setDeviceNumber(mAntManager
                            .getBufferThreshold());
                    break;
                case PairingDialog.PROX_ID:
                    mShownDialog.setProximityThreshold(mAntManager
                            .getProximityThreshold());
                    break;
                default:
                    // Other ID's don't matter
                    break;
            }
        }*/
    }

    @Override
    public void onServiceDisconnected(ComponentName componentName) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Retrieve application persistent data.
     */
    private void loadConfiguration() {
        // Restore preferences
        mAntManager.setDeviceNumberHRM((short) SettingManager.getInstance().getAntHRMDeviceNumber());
    }
}
